package weaver.interfaces.jjy.duss.hr;

import com.sap.mw.jco.JCO;
import com.weaver.general.BaseBean;
import weaver.interfaces.jjy.duss.util.SAPComMehtod;
import weaver.interfaces.jjy.duss.util.SAPConnPool;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 促销员兼职
 * @author: Dusongsong
 * @create: 2019-11-26
 */
public class HR037 {

    public Map execute(Map<String,String> map) {

        SAPConnPool SAPConn = new SAPConnPool();
        JCO.Client myConnection = SAPConn.getConnection();
        JCO.Function bapi = SAPConn.excuteBapi("ZFM_HR_PERNR");

        JCO.ParameterList input=bapi.getImportParameterList();//输入参数和结构处理

        //入参为字段
        input.setValue("HR037","JIEKNO");
        input.setValue(map.get("IV_PERNR"), "IV_PERNR");

        //入参为结构
        JCO.Structure stu1=input.getStructure("PS0000");
        stu1.setValue(map.get("PERNR"), "PERNR");        //员工号
        stu1.setValue(map.get("MASSN"), "MASSN");        //事件类型
        stu1.setValue(map.get("MASSG"), "MASSG");        //事件原因
        stu1.setValue(map.get("BEGDA"),"BEGDA");         //开始日期

        JCO.Structure stu2=input.getStructure("PS0001");
        stu2.setValue(map.get("ABKRS"), "ABKRS");          //工资核算范围
        stu2.setValue(map.get("PERSG"), "PERSG");          //员工组
        stu2.setValue(map.get("PERSK"), "PERSK");          //员工子组
        stu2.setValue(map.get("PERNR"), "PERNR");          //员工号

        JCO.Structure stu9 = input.getStructure("PS0009");
        stu9.setValue(map.get("BANKL"), "BANKL");              //银行代码
        stu9.setValue(map.get("BANKN"), "YHKH");              //银行卡号

        JCO.Structure stu3=input.getStructure("PS9004");
        stu3.setValue(map.get("ZHR_PERSG"), "ZHR_PERSG");  //员工组
        stu3.setValue(map.get("ZHR_PERSA"), "ZHR_PERSA");  // 员工子组
        stu3.setValue(map.get("ZHR_RZMD"), "ZHR_RZMD");    //任职门店
        stu3.setValue(map.get("ZHR_RZGW"), "ZHR_RZGW");    //任职岗位
        stu3.setValue(map.get("ZHR_GYS"), "ZHR_GYS");      //供应商名称
        stu3.setValue(map.get("ZHR_RZLX"), "ZHR_RZLX");    //任职类型
        stu3.setValue(map.get("BEGDA"), "BEGDA");          //开始日期
        stu3.setValue(map.get("PERNR"), "PERNR");          //人员编号
        stu3.setValue(map.get("ZHR_ZW"), "ZHR_ZW");        //职务名称
        stu3.setValue(map.get("ZHR_ZWXL"), "ZHR_ZWXL");    //职务序列
        stu3.setValue(map.get("ZHR_ZWC"), "ZHR_ZWC");      //职务簇

        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回处理结果以及日志
        Map<String, String> mapreturn = new HashMap<>();
        JCO.Structure stu = out.getStructure("EV_OUTPUT");
        mapreturn.put("flag",(String) stu.getValue("ZFLAG"));
        mapreturn.put("message",(String) stu.getValue("ZMESG"));
        if("E".equals(mapreturn.get("flag"))){
            //遍历
            BaseBean baseBean = new BaseBean();
            String structure = baseBean.getPropValue("SAPAllTable","structure");//所有结构
            String[] structures = structure.split(",");
            String table = baseBean.getPropValue("SAPAllTable","table");//所有表
            String[] tables = table.split(",");
            mapreturn = SAPComMehtod.SAPreturnS(structures, out, tables, Table00);
            baseBean.writeLog("SAP返回结果"+mapreturn.toString());
        }
        JCO.releaseClient(myConnection);
        return mapreturn;
    }
}

